function aafData = RemoveOldData( aafRawData, iRequestedStartingTime )
	%
	global bPrintDebugInformation;
	global tFileID;
	%
	if( numel( aafRawData ) == 0 )
		%
		aafData = [];
		%
		if( bPrintDebugInformation )
			%
			fprintf(tFileID, 'All the raw data have been removed, removing noting.\n');
			%
		end;%
		%
		return;
		%
	end;%
	%
	% DEBUG
	if( bPrintDebugInformation )
		%
		fprintf(tFileID, 'Removing the old data. Starting time = %d\n', iRequestedStartingTime);
		%
	end;%
	%	
	% for readability
	TIME_COLUMN = 2;
	%
	% find where the last sample has been inserted
	[ iEndingTime, iIndexOfEndingTime ] = max( aafRawData( :, TIME_COLUMN ) );
	%
	if( iRequestedStartingTime >= iEndingTime )
		%
		if( bPrintDebugInformation )
			%
			fprintf(tFileID, 'Requested a starting time that is bigger then the ending time => returning\n')
			%
		end;%
		%
		aafData = [];
		return;
		%
	end;%
	%
	% check for errors
	if( numel(iIndexOfEndingTime) ~= 1 )
		%
		warning('something wrong in RemoveOldData')
		%
	end;%
	%
	% sort the data in the circular buffer
	if( iIndexOfEndingTime < size( aafRawData, 1 ) )
		%
		aafSortedData = [	aafRawData( iIndexOfEndingTime+1:end, : );	...
							aafRawData( 1:iIndexOfEndingTime, : )		];
		%
	else%
		%
		aafSortedData = aafRawData;
		%
	end;%
	%
	% remove the rows corresponding to the too old data
	iIndexOfNewData		= find(aafRawData(:, TIME_COLUMN) > iRequestedStartingTime, 1, 'first');
	aafData				= aafRawData(iIndexOfNewData:end, :);
	%
	% DEBUG
	if( bPrintDebugInformation )
		%
		fprintf(tFileID, 'Ended removing the old data. iIndexOfEndingTime = %d\n', iIndexOfEndingTime);
		%
	end;%
	%	
end % function

